<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:x="https://www.texmacs.org/2002/extensions" xmlns:m="http://www.w3.org/1998/Math/MathML">
  <head>
    <title>TeXmacs notes</title>
    <meta content="TeXmacs 1.99.16" name="generator"></meta>
    <link href="../resources/notes-base.css" type="text/css" rel="stylesheet"></link>
    <link href="../resources/blog-icon.png" rel="icon"></link>
    <script src="../resources/highlight.pack.js" language="javascript" defer></script>
    <script src="../resources/notes-base.js" language="javascript" defer></script>
  </head>
  <body>
    <div class="notes-header">
      <p>
        <img class="image" src="../resources/texmacs-blog-transparent.png" width="28.116784"></img><span style="margin-left: 2pt"></span><a href="./main.html">[main]</a><em
        class="notes-header-name">Notes on TeXmacs</em>
      </p>
    </div>
    <h1 id="auto-1">Modular graphics with <class style="font-variant: small-caps">Scheme</class><span style="margin-left: 1em"></span></h1>
    <p>
      This post is a part of a series of <class style="font-variant: small-caps">Scheme</class> graphics
      in TeXmacs. Other posts in the same series are <a href="./scheme-graphics.html">Composing
      TeXmacs graphics with Scheme</a> and <a href="./scheme-graphics-embedding.html">Embedding graphics
      composed with Scheme into documents</a>; we also plan to write a post on
      how to generate <class style="font-variant: small-caps">Scheme</class> graphics with external
      files.
    </p>
    <p>
      Like in the other posts of the series, we assume that the reader is
      familiar with simple Scheme syntax. We link again to the <class style="font-variant: small-caps">Wikipedia</class>
      book <a href="https://en.wikibooks.org/wiki/Scheme_Programming">Scheme programming</a> and to <a href="http://www.shido.info/lisp/idx_scm_e.html">Yet Another Scheme
      Tutorial</a> by Takafumi Shido as two possible web resources for
      learning <class style="font-variant: small-caps">Scheme</class>.
    </p>
    <p>
      TeXmacs graphics provide a set of elementary objects (points, polylines,
      splines and so on). It would be nice to have at hand functions to deal
      with complex objects, which can be seen as unions of elementary objects:
      for example,  a triangle in a half-circle is the union of a polyline (to
      represent the triangle) with the half-circle, which in turn is the union
      of a polyline (the diameter of the half-circle) and an arc.
    </p>
    <p>
      We would like to name complex objects and to transform them as units:
      for example translate them or change the line style or the color for all
      of the object components; naming complex objects will make our code
      clearer when we deal with them&mdash;and for example we use them as
      building blocks of even more complex objects.
    </p>
    <p>
      In TeXmacs there is a partially-implemented interface for dealing with
      complex graphics objects  (see <class class="tmweb-menu" style="font-family: sans-serif">Help</class>&rarr;<class
      class="tmweb-menu" style="font-family: sans-serif">Scheme extensions</class>&rarr;<class class="tmweb-menu" style="font-family: sans-serif">Scheme
      interface for the graphical mode</class><a id="auto-2"></a> and the <tt class="verbatim">.scm</tt>
      files in the <tt class="verbatim">progs/graphics/</tt> directory in the TeXmacs
      distribution). In particular, graphics can be grouped using the
      primitive <font class="tmweb-markup">gr-group</font>.
    </p>
    <p>
      In this post, we will develop a small interface of our own; we will show
      how to compose and use in a drawing complex graphical objects, how to
      shift them and how to set properties of already-existing complex
      objects.
    </p>
    <h2 id="auto-3">1.<span style="margin-left: 1em"></span>Composing complex objects<span style="margin-left: 1em"></span></h2>
    <p>
      In <class style="font-variant: small-caps">Scheme</class>, a natural way of composing complex
      objects is joining the building blocks into a list. To get TeXmacs to
      draw the objects represented by our (possibly nested) lists, we need to
      transform them into lists that conform to the TeXmacs graphical input.
    </p>
    <p>
      The input for graphics in TeXmacs <class style="font-variant: small-caps">Scheme</class> is a list
      which starts with the symbol <tt class="verbatim scheme">graphics</tt>, whose elements
      are elementary graphical objects. Each elementary graphical object is a
      list, which starts with one of these symbols: <tt class="verbatim scheme">point</tt>, <tt
      class="verbatim scheme">line</tt>, <tt class="verbatim scheme">cline</tt>, <tt class="verbatim scheme">spline</tt>, <tt
      class="verbatim scheme">cspline</tt>, <tt class="verbatim scheme">arc</tt>, <tt class="verbatim scheme">carc</tt>, <tt
      class="verbatim scheme">text-at</tt>, <tt class="verbatim scheme">math-at</tt>, <tt class="verbatim scheme">document-at</tt>,
      and can be optionally wrapped in a list starting with the symbol <tt
      class="verbatim scheme">with</tt> that sets properties.
    </p>
    <p>
      One possible way to turn an arbitrarily nested list of elementary
      objects (a complex object, that is) into the flat list of lists that
      TeXmacs expects is flattening it recursively, stopping the recursive
      flattening every time we find one of the symbols that indicate the start
      of a graphical object (including the symbol <tt class="verbatim scheme">with</tt>).
    </p>
    <p>
      The following group of three functions does that. The main function is
      adapted from <a href="https://stackoverflow.com/a/33338401">one of the answers</a> to this <a href="https://stackoverflow.com/questions/33338078/flattening-a-list-in-scheme">Stack
      Overflow question</a>.
    </p>
    <p>
      <div style="display: inline">
        <a id="auto-4"></a>
      </div>
      <h5>Flattening nested lists of graphical objects<span style="margin-left: 1em"></span></h5>
    </p>
    <div class="compact-block" style="margin-top: 0.5em; text-indent: 0em">
      <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
        <p>
          <tt class="verbatim scheme">denest-test</tt> is a test to stop denestification when
          one finds one of the symbols in the list <tt class="verbatim scheme">objects-list</tt>
          or the symbol <tt class="verbatim scheme">with</tt>.
        </p>
        <p>
          We build it up from an <tt class="verbatim scheme">object-test</tt>, which check
          membership in <tt class="verbatim scheme">object-list</tt>. <tt class="verbatim scheme">object-test</tt>
          itself will help later too, in a function that applies properties to
          all of the elementary components of an object.
        </p>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define objects-list '(point line cline spline arc
                    carc text-at math-at document-at))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define (object-test expr)   (not (equal?
        (filter (lambda (x) (equal? x expr)) objects-list)
        '())))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define (denest-test expr)
  (or
   (object-test expr)
   (equal? expr 'with)))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
        <p>
          <tt class="verbatim scheme">denestify-conditional</tt> flattens a list recursively,
          stopping the recursion if it meets one of the symbols in <tt class="verbatim scheme">objects-list</tt>
          or the symbol <tt class="verbatim scheme">with</tt>.
        </p>
        <p>
          <tt class="verbatim scheme">denestify-conditional</tt> is not tail-recursive; we
          write it in this way as it is simpler than the tail-recursive
          version and it will work fairly, as in these examples we will apply
          it to short lists.
        </p>
        <p>
          A tail-recursive version of the function is given in <a href="https://stackoverflow.com/a/33338608">another
          answer</a> to the same StackExchange question which we used as
          starting point.
        </p>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">

;; start from the answer https://stackoverflow.com/a/33338401 
;; to the Stack Overflow question
;; https://stackoverflow.com/q/33338078/flattening-a-list-in-scheme

;;(define (denestify lst)
;;  (cond ((null? lst) '())
;;        ((pair? (car lst))
;;         (append (denestify (car lst))
;;                 (denestify (cdr lst))))
;;        (else (cons (car lst) (denestify (cdr lst))))))

;; This function is not tail-recursive; 
;; see https://stackoverflow.com/a/33338608
;; for a tail-recursive function
  (define (denestify-conditional lst)
    (cond ((null? lst) '())
          ((pair? (car lst))
           ;; If the car of (car lst) is 'with or another
           ;; of the symbols in denest-test, we cons it
           (if (denest-test (car (car lst)))
               (cons (car lst)
                     (denestify-conditional (cdr lst)))
               ;; otherwise we flatten it with recursion,
               ;; obtaining a flat list, and append it to
               ;; the flattened rest of the list, in this
               ;; way flattening the combination of the
               ;; two lists
               (append (denestify-conditional (car lst))
                       (denestify-conditional (cdr lst)))))
          ;; (car lst) is an atom
          (else (if (denest-test (car lst))
               ;; test presence of (car lst) in the list
               ;; of symbols that stop denestification
                    lst ;; we leave lst as it is
               ;; otherwise we cons (car lst) onto the
               ;; flattened version of (cdr lst)
                    (cons (car lst) 
                          (denestify-conditional 
                             (cdr lst)))))))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="margin-bottom: 0.5em; text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <p>
      <div style="display: inline">
        <a id="auto-5"></a>
      </div>
      <h5>Definition of basic graphical objects<span style="margin-left: 1em"></span></h5>
    </p>
    <p>
      Let us define a function for generating points, and use that to define
      some graphical objects (the same objects of our previous posts). We will
      then combine these objects in a complex unit and show that TeXmacs draws
      it using our <tt class="verbatim scheme">denestify-conditional</tt> function.
    </p>
    <div class="compact-block" style="margin-top: 0.5em; text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define (pt x y)
  &lsquo;(point ,(number-&gt;string x) ,(number-&gt;string y)))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
        <p>
          
        </p>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
        <p>
          We will work with a circle so we need &pi;!
        </p>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define pi (acos -1))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
        <p>
          Define points for the triangle
        </p>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define pA (pt -2 0))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define pB (pt 2 0))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
        <p>
          Then the third point of the triangle, on the circumference, defined
          with the help of two variables <tt class="verbatim scheme">xC</tt> and <tt class="verbatim scheme">yC</tt>:
        </p>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define xC (- (* 2 (cos (/ pi 3)))))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define yC (* 2 (sin (/ pi 3))))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define pC (pt xC yC))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
        <p>
          Finally the points at which we will mark the triangle's vertices
          with letters:
        </p>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define tA (pt -2.3 -0.5))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define tB (pt 2.1 -0.5))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define tC (pt (- xC 0.2) (+ yC 0.2)))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
        <p>
          Use points to build up a drawing, where each object is typed down as
          a list.
        </p>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><pre class="verbatim" xml:space="preserve">
Scheme] </pre></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(stree-&gt;tree
 &lsquo;(with &quot;gr-geometry&quot;     
      (tuple &quot;geometry&quot; &quot;400px&quot; &quot;300px&quot; &quot;center&quot;)
    &quot;font-shape&quot; &quot;italic&quot;
    (graphics
      ;; the arc and the line together make the semicircle
      (with &quot;color&quot; &quot;black&quot;  (arc ,pA ,pC ,pB))
      (with &quot;color&quot; &quot;black&quot;  (line ,pA ,pB))
      ;; a closed polyline for the triangle
      (with &quot;color&quot; &quot;red&quot; &quot;line-width&quot; &quot;1pt&quot; 
            (cline ,pA ,pB ,pC))
      ;; add letters using text-at
      (with &quot;color&quot; &quot;black&quot;  (text-at &quot;A&quot; ,tA))
      (with &quot;color&quot; &quot;black&quot;  (text-at &quot;B&quot; ,tB))
      (with &quot;color&quot; &quot;black&quot;  (text-at &quot;C&quot; ,tC))
      ;; finally decorate with the TeXmacs symbol
      (with &quot;color&quot; &quot;blue&quot;  &quot;font-shape&quot; &quot;upright&quot; 
            (text-at (TeXmacs) ,(pt -0.55 -0.75))))))
;; and close all of the parentheses!!!</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="margin-bottom: 0.5em; text-indent: 0em">
      <p>
        <tt class="verbatim"><div align="justify">
          <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
            <p>
              <i><img src="modular-scheme-graphics-1.png" style="margin-left: 0em; margin-bottom: 0em; margin-right: 0em; margin-top: 0em; vertical-align: -10.9949898989899em; height: 21.9899797979798em"></img></i>
            </p>
          </div>
        </div></tt>
      </p>
    </div>
    <p>
      <div style="display: inline">
        <a id="auto-6"></a>
      </div>
      <h5>Combination of individual graphical objects into complex
      objects<span style="margin-left: 1em"></span></h5>
    </p>
    <p>
      Let us join graphical objects as lists to form complex graphical
      objects. We will use the conditional flattening inside the graphical
      list to express our complex objects in the way TeXmacs expects them.
    </p>
    <div class="compact-block" style="margin-top: 0.5em; text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define triangle &lsquo;(with &quot;color&quot; &quot;red&quot; &quot;line-width&quot; &quot;1pt&quot;
                        (cline ,pA ,pB ,pC)))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define half-circle &lsquo;(
(with &quot;color&quot; &quot;black&quot; (arc ,pA ,pC ,pB))
(with &quot;color&quot; &quot;black&quot; (line ,pA ,pB))))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define letters &lsquo;((with &quot;color&quot; &quot;black&quot;  (text-at &quot;A&quot; ,tA))
                  (with &quot;color&quot; &quot;black&quot;  (text-at &quot;B&quot; ,tB))
                  (with &quot;color&quot; &quot;black&quot;  (text-at &quot;C&quot; ,tC))))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define caption &lsquo;((with &quot;color&quot; &quot;blue&quot;  
                        &quot;font-shape&quot; &quot;upright&quot;
            (text-at (TeXmacs) ,(pt -0.55 -0.75)))))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><pre class="verbatim" xml:space="preserve">
Scheme] </pre></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(stree-&gt;tree
 &lsquo;(with &quot;gr-geometry&quot;
      (tuple &quot;geometry&quot; &quot;400px&quot; &quot;300px&quot; &quot;center&quot;)
    &quot;font-shape&quot; &quot;italic&quot;
    ,(denestify-conditional &lsquo;(graphics
                             ,triangle
                             ,letters
                             ,half-circle
                             ,caption))))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="margin-bottom: 0.5em; text-indent: 0em">
      <p>
        <tt class="verbatim"><div align="justify">
          <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
            <p>
              <i><img src="modular-scheme-graphics-2.png" style="margin-left: 0em; margin-bottom: 0em; margin-right: 0em; margin-top: 0em; vertical-align: -10.9949898989899em; height: 21.9899797979798em"></img></i>
            </p>
          </div>
        </div></tt>
      </p>
    </div>
    <p>
      <div style="display: inline">
        <a id="auto-7"></a>
      </div>
      <h5>A function for complex graphics<span style="margin-left: 1em"></span></h5>
    </p>
    <p>
      To write less ourselves, we can define a function that flattens graphics
      lists and wraps them with the TeXmacs syntax:
    </p>
    <div class="compact-block" style="margin-top: 0.5em; text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define (scheme-graphics x-size y-size alignment graphics-list)
  (stree-&gt;tree
   &lsquo;(with &quot;gr-geometry&quot; 
        (tuple &quot;geometry&quot; ,x-size ,y-size alignment)
        &quot;font-shape&quot; &quot;italic&quot;
        ,(denestify-conditional 
            &lsquo;(graphics ,graphics-list)))))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
        <p>
          Let's use it:
        </p>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><pre class="verbatim" xml:space="preserve">
Scheme] </pre></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(scheme-graphics &quot;400px&quot; &quot;300px&quot; &quot;center&quot; &lsquo;(
,half-circle
,triangle
,letters
,caption))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="margin-bottom: 0.5em; text-indent: 0em">
      <p>
        <tt class="verbatim"><div align="justify">
          <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
            <p>
              <i><img src="modular-scheme-graphics-1.png" style="margin-left: 0em; margin-bottom: 0em; margin-right: 0em; margin-top: 0em; vertical-align: -10.9949898989899em; height: 21.9899797979798em"></img></i>
            </p>
          </div>
        </div></tt>
      </p>
    </div>
    <h2 id="auto-8">2.<span style="margin-left: 1em"></span>Manipulation of complex objects<span style="margin-left: 1em"></span></h2>
    <p>
      We would like to manipulate complex objects as units. Let's see how to
      translate them; one can in a similar way rotate and stretch them
      (perhaps with respect to reference points which are calculated from the
      objects themselves). We will then see how to apply properties to all of
      the components of an object.
    </p>
    <p>
      <div style="display: inline">
        <a id="auto-9"></a>
      </div>
      <h5>Translate complex objects<span style="margin-left: 1em"></span></h5>
    </p>
    <p>
      Since all objects are made out of points (that is, lists that start with
      the symbol <tt class="verbatim scheme">point</tt>), we need to translate each point which
      the list is composed of.
    </p>
    <p>
      We do it by mapping a translation function recursively
      <div class="footnote">
        <font style="font-size: 80.0%"><div align="justify">
          <div style="margin-left: 0px">
            <div style="margin-right: 0px">
              <class style="font-style: normal"><p>
                1. Neither the function for translation nor the one for
                property-setting are tail-recursive, but they are sufficient
                for our examples. Moreover the stack dimension in the calls to
                these function is determined by how much lists are nested,
                which keeps the stack dimension small.
              </p></class>
            </div>
          </div>
        </div></font>
      </div>
      <span style="margin-left: 0em"></span>
      <a id="footnr-1"></a>
      <sup><class style="font-style: normal"><a href="#footnote-1">1</a></class></sup>
      onto the list that represents a complex object; in this recursive
      mapping we distinguish between expressions that represent points (that
      have to be translated) and expressions that represent something else
      (that have to be left as they are).
    </p>
    <p>
      The distinction is made when the recursion either gets to a point or
      gets to an atom: if it does get to an atom, then the translation
      function acts as the identity function. Here is the algorithm applied to
      a list:
    </p>
    <ul>
      <li>
        <p>
          If the list starts with <tt class="verbatim scheme">point</tt>, we apply the function
          that translates the point
        </p>
      </li>
      <li>
        <p>
          If the list does not start with <tt class="verbatim scheme">point</tt>, we map the
          translation function onto the list
        </p>
      </li>
      <li>
        <p>
          If while mapping we meet an atom, we leave it as it is
        </p>
      </li>
    </ul>
    <div class="compact-block" style="margin-top: 0.5em; text-indent: 0em">
      <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
        <p>
          A function to translate points
        </p>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define (translate-point point delta-vect)
  (let ((coord (map string-&gt;number (cdr point))))
    (pt (+ (car coord) (car delta-vect))
        (+ (cadr coord) (cadr delta-vect)))))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
        <p>
          The general translation function. It is called <tt class="verbatim scheme">translate-element</tt>
          rather than <tt class="verbatim scheme">translate-object</tt> because it applies to
          all elements, including atoms.
        </p>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define (translate-element element delta-vect)
  (cond ((list? element)
     (if (equal? (car element) 'point)
        (translate-point element delta-vect)
        (map (lambda (x) 
               (translate-element x delta-vect)) 
             element)))
        (else element)))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
        <p>
          Let's apply this function to a polyline to see its effect on the
          <class style="font-variant: small-caps">Scheme</class> expression:
        </p>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><pre class="verbatim" xml:space="preserve">
Scheme] </pre></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(translate-element &lsquo;((line ,(pt 1 2) ,(pt 2 3) ,(pt 3 4))
                 (text-at TeXmacs ,(pt -1 -1))) '(1 1))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <p>
        <tt class="verbatim"><div align="justify">
          <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
            <p>
              ((line (point &quot;2&quot; &quot;3&quot;) (point &quot;3&quot;
              &quot;4&quot;) (point &quot;4&quot; &quot;5&quot;)) (text-at
              TeXmacs (point &quot;0&quot; &quot;0&quot;)))
            </p>
          </div>
        </div></tt>
      </p>
    </div>
    <div class="compact-block" style="margin-bottom: 0.5em; text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <p>
      Let us now use our translation function on a complex object in a
      drawing: the triangle inscribed in the half-circle we first drew by
      listing all of the elementary objects and then by combining the complex
      <tt class="verbatim scheme">triangle</tt>, <tt class="verbatim scheme">half-circle</tt> and <tt class="verbatim scheme">letter</tt>
      objects (we are then going to add the TeXmacs caption!).
    </p>
    <p>
      This time, we define the whole drawing as a unit, calling it <tt class="verbatim scheme">triangle-in-half-circle</tt>;
      we will need to remember to unquote the symbol <tt class="verbatim scheme">triangle-in-half-circle</tt>
      when placing it inside lists defined through quasiquoting.
    </p>
    <div class="compact-block" style="margin-top: 0.5em; text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define triangle-in-half-circle  &lsquo;(
   ,half-circle
   ,triangle
   ,letters))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
        <p>
          Draw it by placing it in the list argument of the <tt class="verbatim scheme">scheme-graphics</tt>
          function:
        </p>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><pre class="verbatim" xml:space="preserve">
Scheme] </pre></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(scheme-graphics &quot;400px&quot; &quot;300px&quot; &quot;center&quot; 
      &lsquo;(,triangle-in-half-circle ,caption)))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <p>
        <tt class="verbatim"><div align="justify">
          <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
            <p>
              <i><img src="modular-scheme-graphics-1.png" style="margin-left: 0em; margin-bottom: 0em; margin-right: 0em; margin-top: 0em; vertical-align: -10.9949898989899em; height: 21.9899797979798em"></img></i>
            </p>
          </div>
        </div></tt>
      </p>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
        <p>
          Now add to the drawing a translated copy of <tt class="verbatim scheme">triangle-in-half-circle</tt>
          and the TeXmacs caption (translating that too):
        </p>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><pre class="verbatim" xml:space="preserve">
Scheme] </pre></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(scheme-graphics &quot;400px&quot; &quot;300px&quot; &quot;center&quot; 
&lsquo;( ,triangle-in-half-circle
   ,(translate-element triangle-in-half-circle '(1.0 -1.5))
   ,(translate-element caption '(1.0 -1.5))))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="margin-bottom: 0.5em; text-indent: 0em">
      <p>
        <tt class="verbatim"><div align="justify">
          <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
            <p>
              <i><img src="modular-scheme-graphics-3.png" style="margin-left: 0em; margin-bottom: 0em; margin-right: 0em; margin-top: 0em; vertical-align: -10.9949898989899em; height: 21.9899797979798em"></img></i>
            </p>
          </div>
        </div></tt>
      </p>
    </div>
    <p>
      <div style="display: inline">
        <a id="auto-10"></a>
      </div>
      <h5>Manipulate object properties<span style="margin-left: 1em"></span></h5>
    </p>
    <p>
      We write a simple function which wraps each elementary object in a <tt
      class="verbatim scheme">with</tt>, placing it inside with respect to any other <tt class="verbatim scheme">with</tt>
      construct the object might be already placed in. This function, applied
      a few times, generates deeply nested lists that may be difficult to
      read; a more refined function would check if the object is already
      inside a <tt class="verbatim scheme">with</tt> construct and if it is, modify the <tt
      class="verbatim scheme">with</tt> list rather than adding another one. We prefer the
      simple function to the refined one to keep this post to the point
      (&ldquo;modular graphics&rdquo;).
    </p>
    <p>
      The <tt class="verbatim scheme">with</tt> needs to be placed as innermost wrapping
      construct for each element so that the new property will prevail onto
      pre-existing properties (<tt class="verbatim scheme">with</tt>s are scoping constructs).
    </p>
    <p>
      The <tt class="verbatim scheme">apply-property</tt> function is built with the same logic
      as the <tt class="verbatim scheme">translate-element</tt> function. When applied to a
      list, it first checks if the list starts with one of the
      &ldquo;graphical object&rdquo; symbols; if it does, <tt class="verbatim scheme">apply-property</tt>
      wraps it in a <tt class="verbatim scheme">with</tt> construct; if it does not, <tt class="verbatim scheme">apply-property</tt>
      maps itself onto the list elements. When applied to an atom, <tt class="verbatim scheme">apply-property</tt>
      returns the input.
    </p>
    <p>
      In this way the function seeks recursively inside the lists of all the
      graphical objects, and applies the desired property to each.
    </p>
    <div class="compact-block" style="margin-top: 0.5em; text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define (apply-property element name value)
  (cond 
    ((list? element)
        (if (object-test (car element))
            &lsquo;(with ,name ,value ,element)
            (map (lambda (x) (apply-property x name value))
                 element)))
     (else element)))        </pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
        <p>
          Let's apply dashing to the <tt class="verbatim scheme">triangle</tt> object (let us
          view the <class style="font-variant: small-caps">Scheme</class> lists):
        </p>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><pre class="verbatim" xml:space="preserve">
Scheme] </pre></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(apply-property triangle &quot;dash-style&quot; &quot;11100&quot;)</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <p>
        <tt class="verbatim"><div align="justify">
          <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
            <p>
              (with &quot;color&quot; &quot;red&quot; &quot;line-width&quot;
              &quot;1pt&quot; (with &quot;dash-style&quot; &quot;11100&quot;
              (cline (point &quot;-2&quot; &quot;0&quot;) (point &quot;2&quot;
              &quot;0&quot;) (point &quot;-1.0&quot;
              &quot;1.73205080756888&quot;))))
            </p>
          </div>
        </div></tt>
      </p>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
        <p>
          We act on a more complex object in the same way as we do on a
          simpler object&mdash;we now apply dashing to the translated copy of
          <tt class="verbatim scheme">triangle-in-half-circle</tt>:
        </p>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><pre class="verbatim" xml:space="preserve">
Scheme] </pre></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(apply-property
  (translate-element triangle-in-half-circle '(1.0 -1.5))
  &quot;dash-style&quot; &quot;11100&quot;)</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <p>
        <tt class="verbatim"><div align="justify">
          <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
            <p>
              (((with &quot;color&quot; &quot;black&quot; (with
              &quot;dash-style&quot; &quot;11100&quot; (arc (point
              &quot;-1.0&quot; &quot;-1.5&quot;) (point &quot;0.0&quot;
              &quot;0.23205080756888&quot;) (point &quot;3.0&quot;
              &quot;-1.5&quot;)))) (with &quot;color&quot; &quot;black&quot;
              (with &quot;dash-style&quot; &quot;11100&quot; (line (point
              &quot;-1.0&quot; &quot;-1.5&quot;) (point &quot;3.0&quot;
              &quot;-1.5&quot;))))) (with &quot;color&quot; &quot;red&quot;
              &quot;line-width&quot; &quot;1pt&quot; (with
              &quot;dash-style&quot; &quot;11100&quot; (cline (point
              &quot;-1.0&quot; &quot;-1.5&quot;) (point &quot;3.0&quot;
              &quot;-1.5&quot;) (point &quot;0.0&quot;
              &quot;0.23205080756888&quot;)))) ((with &quot;color&quot;
              &quot;black&quot; (with &quot;dash-style&quot; &quot;11100&quot;
              (text-at &quot;A&quot; (point &quot;-1.3&quot;
              &quot;-2.0&quot;)))) (with &quot;color&quot; &quot;black&quot;
              (with &quot;dash-style&quot; &quot;11100&quot; (text-at
              &quot;B&quot; (point &quot;3.1&quot; &quot;-2.0&quot;)))) (with
              &quot;color&quot; &quot;black&quot; (with &quot;dash-style&quot;
              &quot;11100&quot; (text-at &quot;C&quot; (point &quot;-0.2&quot;
              &quot;0.43205080756888&quot;))))))
            </p>
          </div>
        </div></tt>
      </p>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
        <p>
          Placing our objects in the list argument of <tt class="verbatim scheme">scheme-graphics</tt>,
          we obtain the drawing in a modular way:
        </p>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><pre class="verbatim" xml:space="preserve">
Scheme] </pre></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(scheme-graphics &quot;400px&quot; &quot;300px&quot; &quot;center&quot; &lsquo;(
,triangle-in-half-circle
,(apply-property
  (translate-element triangle-in-half-circle '(1.0 -1.5))
  &quot;dash-style&quot; &quot;11100&quot;)
,(translate-element caption '(1.0 -1.5))))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <p>
        <tt class="verbatim"><div align="justify">
          <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
            <p>
              <i><img src="modular-scheme-graphics-4.png" style="margin-left: 0em; margin-bottom: 0em; margin-right: 0em; margin-top: 0em; vertical-align: -10.9949898989899em; height: 21.9899797979798em"></img></i>
            </p>
          </div>
        </div></tt>
      </p>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
        <p>
          <tt class="verbatim scheme">apply-property</tt> and <tt class="verbatim scheme">translate-element</tt>
          can be applied in both orders. In the previous example we translated
          first the object, then we applied the dashing; here we apply the
          dashed style first, then we translate the object.
        </p>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><pre class="verbatim" xml:space="preserve">
Scheme] </pre></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(scheme-graphics &quot;400px&quot; &quot;300px&quot; &quot;center&quot; &lsquo;(
,triangle-in-half-circle
,(translate-element   (apply-property
   triangle-in-half-circle   &quot;dash-style&quot; &quot;11100&quot;)
  '(1.0 -1.5))
,(translate-element caption '(1.0 -1.5))))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <p>
        <tt class="verbatim"><div align="justify">
          <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
            <p>
              <i><img src="modular-scheme-graphics-4.png" style="margin-left: 0em; margin-bottom: 0em; margin-right: 0em; margin-top: 0em; vertical-align: -10.9949898989899em; height: 21.9899797979798em"></img></i>
            </p>
          </div>
        </div></tt>
      </p>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
        <p>
          The last application of <tt class="verbatim scheme">apply-property</tt> prevails, as
          it is set in the innermost <tt class="verbatim scheme">with</tt> list; subobjects
          which have individually-set values of the property will all be set
          to the value fixed by the last application of <tt class="verbatim scheme">apply-property</tt>.
          Here we apply a short-dash style on an object which has long-dashing
          throughout:
        </p>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><pre class="verbatim" xml:space="preserve">
Scheme] </pre></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(scheme-graphics &quot;400px&quot; &quot;300px&quot; &quot;center&quot; &lsquo;(
,triangle-in-half-circle
,(translate-element (apply-property
   (apply-property
   triangle-in-half-circle   &quot;dash-style&quot; &quot;11100&quot;)
  &quot;dash-style&quot; &quot;101010&quot;)
  '(1.0 -1.5))
,(translate-element caption '(1.0 -1.5))))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="margin-bottom: 0.5em; text-indent: 0em">
      <p>
        <tt class="verbatim"><div align="justify">
          <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
            <p>
              <i><img src="modular-scheme-graphics-5.png" style="margin-left: 0em; margin-bottom: 0em; margin-right: 0em; margin-top: 0em; vertical-align: -10.9949898989899em; height: 21.9899797979798em"></img></i>
            </p>
          </div>
        </div></tt>
      </p>
    </div>
    <h2 id="auto-11">3.<span style="margin-left: 1em"></span><class style="font-variant: small-caps">Scheme</class> expressions
    that show what we mean<span style="margin-left: 1em"></span></h2>
    <p>
      We apply again the idea of modularity by assigning to a variable the
      object which we obtain after translation and application of dashing, and
      using the variable to build a drawing. Our code again shows that in
      <class style="font-variant: small-caps">Scheme</class> building blocks combine together well.
    </p>
    <div class="compact-block" style="margin-top: 0.5em; text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><pre class="verbatim" xml:space="preserve">
Scheme] </pre></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define translated-triangle-in-half-circle-short-dashes
  (translate-element
     (apply-property
       (apply-property  triangle-in-half-circle 
                        &quot;dash-style&quot; &quot;11100&quot;)
        &quot;dash-style&quot; &quot;101010&quot;)
     '(1.0 -1.5)))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <p>
        <tt class="verbatim"><div align="justify">
          <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
            <p>
              
            </p>
          </div>
        </div></tt>
      </p>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define translated-caption 
  (translate-element caption '(1.0 -1.5)))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
        <p>
          The drawing is made out of complex objects, but the final expression
          shows what we have in mind: our geometrical construction and a
          shifted replica drawn with short dashes.
        </p>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><pre class="verbatim" xml:space="preserve">
Scheme] </pre></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(scheme-graphics &quot;400px&quot; &quot;300px&quot; &quot;center&quot; &lsquo;(
,triangle-in-half-circle
,translated-triangle-in-half-circle-short-dashes
,translated-caption))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="margin-bottom: 0.5em; text-indent: 0em">
      <p>
        <tt class="verbatim"><div align="justify">
          <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
            <p>
              <i><img src="modular-scheme-graphics-5.png" style="margin-left: 0em; margin-bottom: 0em; margin-right: 0em; margin-top: 0em; vertical-align: -10.9949898989899em; height: 21.9899797979798em"></img></i>
            </p>
          </div>
        </div></tt>
      </p>
    </div>
    <p>
      We can play further. Let's blend the triangle inside the half-circle
      stepwise. Our functions are not sophisticated enough to target a subunit
      of a complex object: applying a line-width to the whole drawing of the
      triangle in the half-circle would eliminate the different line-widths
      for the triangle and arc; for this reason, we use as an example of
      blending in the triangle alone, which is one of the units we defined.
    </p>
    <div class="compact-block" style="margin-top: 0.5em; text-indent: 0em">
      <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
        <p>
          The <tt class="verbatim scheme">blend-in-triangle</tt> function shifts the triangle
          by <tt class="verbatim scheme">delta</tt> times the vector <tt class="verbatim scheme">(1.0
          -1.5)</tt>, applies dashing and a linewidth which is thicker as the
          triangle is closer to being inscribed in the half-circle (we are
          going to use this function for values of <tt class="verbatim scheme">delta</tt> which
          yield positive values of the line thickness).
        </p>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define (blend-in-triangle delta)
  (translate-element   (apply-property
   (apply-property
   triangle
  &quot;dash-style&quot; &quot;101010&quot;)
   &quot;line-width&quot; (string-join 
         &lsquo;(,(number-&gt;string (- 1 delta)) &quot;pt&quot;) &quot;&quot;))
         &lsquo;(,(* 1.0 delta) ,(* -1.5 delta))))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
        <p>
          Let's map this function on a list of <tt class="verbatim scheme">d</tt> values, and
          let us name the object it returns (all lists of objects will be
          flattened by the conditional flattener) in a meaningful way:
        </p>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define delta-lst
       '(0.2 0.4 0.6 0.8)))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(define blend-in-triangle-series
  (map blend-in-triangle delta-lst))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
        <p>
          Here is the triangle blending in into the half-circle <span style="margin-left: 0.16665em"></span>.<span
          style="margin-left: 0.16665em"></span>.<span style="margin-left: 0.16665em"></span>.<span style="margin-left: 0.16665em"></span> or fading
          away!
        </p>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><pre class="verbatim" xml:space="preserve">
Scheme] </pre></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
(scheme-graphics &quot;400px&quot; &quot;300px&quot; &quot;center&quot; &lsquo;(
,blend-in-triangle-series
,triangle-in-half-circle
,translated-caption))</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <p>
        <tt class="verbatim"><div align="justify">
          <div class="ornament" style="background-color:#fff0;border-width:0px;padding-left:0.5em;padding-right:0.5em;border-radius:0px;padding-top:0.5em;padding-bottom:0.5em;display:block;">
            <p>
              <i><img src="modular-scheme-graphics-6.png" style="margin-left: 0em; margin-bottom: 0em; margin-right: 0em; margin-top: 0em; vertical-align: -10.9949898989899em; height: 21.9899797979798em"></img></i>
            </p>
          </div>
        </div></tt>
      </p>
    </div>
    <div class="compact-block" style="margin-bottom: 0.5em; text-indent: 0em">
      <div class="ornament" style="background-color:#ffffdf;border-width:1px;padding-left:0.5em;padding-right:0.5em;border-left-color:#dfdfdf;border-top-color:grey;border-radius:0px;;display:block;">
        <table style="width: 100%">
          <tbody><tr>
            <td style="text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
            <td style="width: 100%; text-align: left; padding-left: 0em; padding-right: 0em; padding-bottom: 0em; padding-top: 0em"><pre class="verbatim" xml:space="preserve">
</pre></td>
          </tr></tbody>
        </table>
      </div>
    </div>
    <p>
      One could wish for more actions. For example, one could wish to find
      intersections of lines which define objects, and assign them to new
      objects. Another example is to define styles as shortcuts to set several
      properties of a graphical object with a single operation; this is among
      the functions in the yet-to-be completed TeXmacs <class style="font-variant: small-caps">Scheme</class>
      graphics code. <class style="font-variant: small-caps">Scheme</class> is promising for
      implementing each of them.
    </p>
    <p>
      As a sketch of an implementation, styles could be defined as lists of
      name-value pairs, maybe association lists (this might allow easier
      error-checking), which can be inserted into <tt class="verbatim scheme">with</tt>
      constructs by a function which first flattens the pairs then appends the
      resulting list into a <tt class="verbatim scheme">'(with &hellip; object)</tt> list at
      the position we indicated with the dots to apply all of the properties
      to <tt class="verbatim scheme">object</tt>. Never mind that the <class style="font-variant: small-caps">Scheme</class>
      syntax to achieve what we want is slightly different from the
      description I gave, it is close enough that I hope it is convincing.
    </p>
    <p>
      About persuasion. I hope that I convinced you that the initial effort of
      setting up <class style="font-variant: small-caps">Scheme</class> functions pays off: one
      constructs a powerful graphical language in which arbitrarily complex
      graphics are treated uniformly.
    </p>
  </body>
</html>